class Http {
	constructor() {
		this.baseURL = "http://47.94.6.186:3001";
	}
	request(option) {
		option = beforeRequest(option);
		option.url = this.baseURL + option.url;
		return new Promise((resolve, reject) => {
			uni.request(option)
				.then(res => {
					const response = beforeResponse(res);
					resolve(response);
				})
				.catch(err => reject(err))
		})
	}
	get(url, params = {}) {
		return this.request({
			url,
			data: params,
			method: "GET"
		})
	}
	post(url, data) {
		return this.request({
			url,
			data,
			method: "POST",
		})
	}
}
const beforeRequest = (config) => {
	return config;
}
const beforeResponse = (response) => {
	return response.data;
}

export default new Http();